package com.sandu.voiceassistant.service

import android.app.Service
import android.content.Intent
import android.os.IBinder
import android.os.Looper
import android.provider.Settings.Global
import android.util.Log
import android.widget.Toast
import com.sandu.voiceassistant.IVoiceInterface
import com.sandu.voiceassistant.VoiceCallBack
import com.sandu.voiceassistant.VoiceInfo
import kotlinx.coroutines.coroutineScope

class VoiceService : Service() {
    var voiceCallBack: VoiceCallBack? = null
    override fun onCreate() {
        super.onCreate()
    }

    override fun onBind(intent: Intent): IBinder {
        return binder;
    }

    private val binder = object : IVoiceInterface.Stub() {
        override fun sendVoice(voiceInfo: VoiceInfo?, callback: VoiceCallBack?) {
            //VoiceInfo中获取语音voiceMsg，以及语音类型 type
            voiceCallBack = callback
            startVoice(voiceInfo)

        }
    }

    fun startVoice(voiceInfo: VoiceInfo?) {
        Log.d("voiceService", voiceInfo?.voiceMsg + voiceInfo?.type)
        voiceCallBack?.onSuccess("success")
        voiceCallBack?.onError("fail")
    }
}